package rdd;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Serializable;

import java.util.Arrays;

public class Spark98 {
    public static void main(String[] args) {
        final SparkConf conf = new SparkConf();
        conf.setMaster("local[*]");
        conf.setAppName("spark");
        final JavaSparkContext jsc = new JavaSparkContext(conf);
        final JavaRDD<Integer> rdd = jsc.parallelize(
                Arrays.asList(1,2,3,4)
        );
        Myvalue mv = new Myvalue();
        rdd.foreach(
                num -> {
                    System.out.println(num);
                    mv.sum += num;
                }
        );
        System.out.println(mv.sum);
        jsc.close();
    }
}

class Myvalue implements Serializable {
    public int sum = 0;
}
